from pyspark.sql.session import SparkSession

# enableHiveSupport：开启hive元数据支持，可以使用hive中的表
spark = SparkSession.builder \
    .master("local") \
    .appName("hive") \
    .config("spark.sql.shuffle.partitions", 1) \
    .getOrCreate()

# 创建表，只在当前代码中有效
spark.sql("""
CREATE TABLE students
(
    id STRING, 
    name STRING,
    age INT,
    sex STRING,
    clazz STRING
) 
USING csv
LOCATION 'file:/D:/code/bigdata35/data/students.txt';
""")

spark.sql("desc formatted students").show(truncate=False)


spark.sql("select * from students").show()